package com.yznote.compileserver.yCompile.io;


import com.yznote.compileserver.yCompile.io.YInput;

import java.io.IOException;

public class YByteArrayInput implements YInput {
    byte[] data;
    int ind;
    public YByteArrayInput(byte[] data){
        this.data = data;
        this.ind = 0;
    }

    @Override
    public int read() {
        if(ind<data.length) {
            return data[ind++];
        }
        return -1;
    }

    @Override
    public int read(byte[] data){
        if(data.length<this.data.length){
            System.arraycopy(this.data,0,data,0,data.length);
            return data.length;
        }else{
            System.arraycopy(this.data,0,data,0,this.data.length);
            return this.data.length;
        }
    }

    @Override
    public void close() throws IOException {
        this.data = null;
    }
}
